Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath({'Ext.ux' : 'extjs4/ux'});
Ext.require([
             'Ext.grid.*',
             'Ext.data.*',
             'Ext.ux.grid.FiltersFeature',
             'Ext.toolbar.Paging',
             'Ext.ux.ajax.JsonSimlet',
             'Ext.ux.ajax.SimManager'
]);
Ext.define('TS.view.rp.RpAPayCheckEditor',{
	extend:'Ext.panel.Panel',
	border: false,
	bodyPadding:0,
	layout: 'border',
	alias: 'widget.rpapaycheckeditor',
	title: '应付款核销',
	config:{
		editing:false
	},
	constructor:function(config) {
		this.initConfig(config);
		this.self.superclass.constructor.call(this,config);
	},
	initComponent:function() {
		var payBillSettle = Ext.create('Ext.panel.Panel',{
			title:'付款结算',
			itemId:'paybillsettle',
		    layout: {
		        type: 'vbox',       // Arrange child items vertically
		        align: 'stretch'    // Each takes up full width
		    },
			items:[
			       {
			    	   xtype:'grid',
			    	   flex:1,
			    	   selModel:{selType:'checkboxmodel',checkOnly:true},
					   multiSelect:true,//运行多选
					   features: [{
					       ftype: 'summary'
					   }],
					   plugins: [
					       {
					    	   ptype:'cellediting',
					    	   clicksToEdit: 1
					       }
				       ],
				       columns:[
								   {header:'年份',dataIndex:'fyear',width:50,align:'right'},
								   {header:'期间',dataIndex:'period',width:50,align:'right'},
						       {
						    	   header:'单据编号',dataIndex:'rpBillCode',width:100,
						    	   summaryType:'count',summaryRenderer: function(value, summaryData, dataIndex) {return '<b>' + Ext.String.format('合计[{0}]:', value) + '</b>'; }
						       },
							   {header:'单据类型',dataIndex:'rpBillName',width:80},
							   {header:'单据日期',dataIndex:'billDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d')},
							   {header:'客户编码',dataIndex:'customer',filterable:true,width:80,renderer:function(value,metaData,record){return record.getcustomer().get('customerCode');}},
							   {header:'客户名称',dataIndex:'customer',width:250,renderer:function(value,metaData,record){return record.getcustomer().get('customerName');}},
							   {header:'已付金额',dataIndex:'settleAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {header:'已核销金额',dataIndex:'checkAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {
								   header:'本次核销金额',dataIndex:'currentCheckAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00'),
								   editor: {
					                    xtype: 'numberfield',
					                    allowBlank: false,
		                	        	fieldStyle:'text-align:right',
		                	        	allowDecimals: true
								   }
							   },
							   {header:'部门',dataIndex:'dept',width:65,renderer:function(value,metaData,record){return record.getdept().get('deptName');}},
							   {header:'业务员',dataIndex:'emp',width:65,renderer:function(value,metaData,record){return record.getemp().get('empName');}},
							   {header:'制单人',dataIndex:'maker',width:65,renderer:function(value,metaData,record){return record.getmaker().get('empName');}},
							   {header:'备注',dataIndex:'remark',width:200}
			    	   ],
					   listeners:{
							'select':function(selModel,record,index) {
								var curchkamt = record.get('settleAmount')-record.get('checkAmount');
								record.set('currentCheckAmount',curchkamt);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'deselect':function(selModel,record,index) {
								record.set('currentCheckAmount',0);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'edit':this.onEdit,
							'beforeedit':this.onBeforeEdit,
							'beforeselect':this.onBeforeSelect,
							'beforedeselect':this.onBeforeDeselect
						}
			       },{
			    	   xtype:'splitter'
			       },
			       {
			    	   xtype:'grid',
			    	   flex:1,
			    	   selModel:{selType:'checkboxmodel',checkOnly:true},
					   multiSelect:true,//运行多选
					   features: [{
					       ftype: 'summary'
					   }],
					   plugins: [
							       {
							    	   ptype:'cellediting',
							    	   clicksToEdit: 1
							       }
					   ],
			    	   columns:[
								   {header:'年份',dataIndex:'fyear',width:50,align:'right'},
								   {header:'期间',dataIndex:'period',width:50,align:'right'},
						       {
						    	   header:'单据编号',dataIndex:'arpBillCode',width:100,
						    	   summaryType:'count',summaryRenderer: function(value, summaryData, dataIndex) {return '<b>' + Ext.String.format('合计[{0}]:', value) + '</b>'; }
						       },
							   {header:'单据类型',dataIndex:'arpBillName',width:80},
							   {header:'日期',dataIndex:'billDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d')},
							   {header:'客户编码',dataIndex:'Customer',filterable:true,width:80,renderer:function(value,metaData,record){return record.getcustomer().get('customerCode');}},
							   {header:'客户名称',dataIndex:'customer',width:250,renderer:function(value,metaData,record){return record.getcustomer().get('customerName');}},
							   {header:'应付金额',dataIndex:'amount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {header:'已核销金额',dataIndex:'checkAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {
								   header:'本次核销金额',dataIndex:'currentCheckAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00'),
								   editor: {
					                    xtype: 'numberfield',
					                    allowBlank: false,
		                	        	fieldStyle:'text-align:right',
		                	        	allowDecimals: true
								   }
							   },
							   {header:'部门',dataIndex:'dept',width:65,renderer:function(value,metaData,record){return record.getdept().get('deptName');}},
							   {header:'业务员',dataIndex:'emp',width:65,renderer:function(value,metaData,record){return record.getemp().get('empName');}},
							   {header:'制单人',dataIndex:'maker',width:65,renderer:function(value,metaData,record){return record.getmaker().get('empName');}},
							   {header:'备注',dataIndex:'remark',width:200}
			    	   ],
						listeners:{
							'select':function(selModel,record,index) {
								var curchkamt = record.get('amount')-record.get('checkAmount');
								record.set('currentCheckAmount',curchkamt);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'deselect':function(selModel,record,index) {
								record.set('currentCheckAmount',0);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'edit':this.onEdit,
							'beforeedit':this.onBeforeEdit,
							'beforeselect':this.onBeforeSelect,
							'beforedeselect':this.onBeforeDeselect
						}
			       }
			]
		});
		var refundBillSettle = Ext.create('Ext.panel.Panel',{
			title:'退款核销',
			itemId:'refundbillsettle',
		    layout: {
		        type: 'vbox',       // Arrange child items vertically
		        align: 'stretch'    // Each takes up full width
		    },
			items:[
			       {
			    	   xtype:'grid',
			    	   flex:1,
			    	   selModel:{selType:'checkboxmodel',checkOnly:true},
					   multiSelect:true,//运行多选
					   features: [{
					       ftype: 'summary'
					   }],
					   plugins: [
							       {
							    	   ptype:'cellediting',
							    	   clicksToEdit: 1
							       }
					   ],
			    	   columns:[
							   {header:'年份',dataIndex:'fyear',width:50,align:'right'},
							   {header:'期间',dataIndex:'period',width:50,align:'right'},
						       {
						    	   header:'单据编号',dataIndex:'rpBillCode',width:100,
						    	   summaryType:'count',summaryRenderer: function(value, summaryData, dataIndex) {return '<b>' + Ext.String.format('合计[{0}]:', value) + '</b>'; }
						       },
							   {header:'单据类型',dataIndex:'rpBillName',width:80},
							   {header:'单据日期',dataIndex:'billDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d')},
							   {header:'客户编码',dataIndex:'customer',filterable:true,width:80,renderer:function(value,metaData,record){return record.getcustomer().get('customerCode');}},
							   {header:'客户名称',dataIndex:'customer',width:250,renderer:function(value,metaData,record){return record.getcustomer().get('customerName');}},
							   {header:'退款金额',dataIndex:'settleAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {header:'已核销金额',dataIndex:'checkAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {
								   header:'本次核销金额',dataIndex:'currentCheckAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00'),
								   editor: {
					                    xtype: 'numberfield',
					                    allowBlank: false,
		                	        	fieldStyle:'text-align:right',
		                	        	allowDecimals: true
								   }
							   },
							   {header:'部门',dataIndex:'dept',width:65,renderer:function(value,metaData,record){return record.getdept().get('deptName');}},
							   {header:'业务员',dataIndex:'emp',width:65,renderer:function(value,metaData,record){return record.getemp().get('empName');}},
							   {header:'制单人',dataIndex:'maker',width:65,renderer:function(value,metaData,record){return record.getmaker().get('empName');}},
							   {header:'备注',dataIndex:'remark',width:200}
			    	   ],
					   listeners:{
							'select':function(selModel,record,index) {
								var curchkamt = record.get('settleAmount')-record.get('checkAmount');
								record.set('currentCheckAmount',curchkamt);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'deselect':function(selModel,record,index) {
								record.set('currentCheckAmount',0);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'edit':this.onEdit,
							'beforeedit':this.onBeforeEdit,
							'beforeselect':this.onBeforeSelect,
							'beforedeselect':this.onBeforeDeselect
						}
			       },
			       {
			    	   xtype:'splitter'
			       },
			       {
			    	   xtype:'grid',
			    	   flex:1,
			    	   selModel:{selType:'checkboxmodel',checkOnly:true},
					   multiSelect:true,//运行多选
					   features: [{
					       ftype: 'summary'
					   }],
					   plugins: [
							       {
							    	   ptype:'cellediting',
							    	   clicksToEdit: 1
							       }
					   ],
			    	   columns:[
								   {header:'年份',dataIndex:'fyear',width:50,align:'right'},
								   {header:'期间',dataIndex:'period',width:50,align:'right'},
						       {
						    	   header:'单据编号',dataIndex:'rpBillCode',width:100,
						    	   summaryType:'count',summaryRenderer: function(value, summaryData, dataIndex) {return '<b>' + Ext.String.format('合计[{0}]:', value) + '</b>'; }
						       },
							   {header:'单据类型',dataIndex:'rpBillName',width:80},
							   {header:'单据日期',dataIndex:'billDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d')},
							   {header:'客户编码',dataIndex:'customer',filterable:true,width:80,renderer:function(value,metaData,record){return record.getcustomer().get('customerCode');}},
							   {header:'客户名称',dataIndex:'customer',width:250,renderer:function(value,metaData,record){return record.getcustomer().get('customerName');}},
							   {header:'已付金额',dataIndex:'settleAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {header:'已核销金额',dataIndex:'checkAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {
								   header:'本次核销金额',dataIndex:'currentCheckAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00'),
								   editor: {
					                    xtype: 'numberfield',
					                    allowBlank: false,
		                	        	fieldStyle:'text-align:right',
		                	        	allowDecimals: true
								   }
							   },
							   {header:'部门',dataIndex:'dept',width:65,renderer:function(value,metaData,record){return record.getdept().get('deptName');}},
							   {header:'业务员',dataIndex:'emp',width:65,renderer:function(value,metaData,record){return record.getemp().get('empName');}},
							   {header:'制单人',dataIndex:'maker',width:65,renderer:function(value,metaData,record){return record.getmaker().get('empName');}},
							   {header:'备注',dataIndex:'remark',width:200}
			    	   ],
					   listeners:{
							'select':function(selModel,record,index) {
								var curchkamt = record.get('settleAmount')-record.get('checkAmount');
								record.set('currentCheckAmount',curchkamt);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'deselect':function(selModel,record,index) {
								record.set('currentCheckAmount',0);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'edit':this.onEdit,
							'beforeedit':this.onBeforeEdit,
							'beforeselect':this.onBeforeSelect,
							'beforedeselect':this.onBeforeDeselect
						}
			       }
			]
		});
		var apayOffsetarecSettle = Ext.create('Ext.panel.Panel',{
			title:'应付款冲应收款',
			itemId:'offsetsettle',
		    layout: {
		        type: 'vbox',       // Arrange child items vertically
		        align: 'stretch'    // Each takes up full width
		    },
			items:[
			       {
			    	   xtype:'grid',
			    	   flex:1,
			    	   selModel:{selType:'checkboxmodel',checkOnly:true},
					   multiSelect:true,//运行多选
					   features: [{
					       ftype: 'summary'
					   }],
					   plugins: [
							       {
							    	   ptype:'cellediting',
							    	   clicksToEdit: 1
							       }
					   ],
			    	   columns:[
								   {header:'年份',dataIndex:'fyear',width:50,align:'right'},
								   {header:'期间',dataIndex:'period',width:50,align:'right'},
						       {
						    	   header:'单据编号',dataIndex:'arpBillCode',width:100,
						    	   summaryType:'count',summaryRenderer: function(value, summaryData, dataIndex) {return '<b>' + Ext.String.format('合计[{0}]:', value) + '</b>'; }
						       },
							   {header:'单据类型',dataIndex:'arpBillName',width:80},
							   {header:'日期',dataIndex:'billDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d')},
							   {header:'客户编码',dataIndex:'Customer',filterable:true,width:80,renderer:function(value,metaData,record){return record.getcustomer().get('customerCode');}},
							   {header:'客户名称',dataIndex:'customer',width:250,renderer:function(value,metaData,record){return record.getcustomer().get('customerName');}},
							   {header:'应付金额',dataIndex:'amount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {header:'已核销金额',dataIndex:'checkAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {
								   header:'本次核销金额',dataIndex:'currentCheckAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00'),
								   editor: {
					                    xtype: 'numberfield',
					                    allowBlank: false,
		                	        	fieldStyle:'text-align:right',
		                	        	allowDecimals: true
								   }
							   },
							   {header:'部门',dataIndex:'dept',width:65,renderer:function(value,metaData,record){return record.getdept().get('deptName');}},
							   {header:'业务员',dataIndex:'emp',width:65,renderer:function(value,metaData,record){return record.getemp().get('empName');}},
							   {header:'制单人',dataIndex:'maker',width:65,renderer:function(value,metaData,record){return record.getmaker().get('empName');}},
							   {header:'备注',dataIndex:'remark',width:200}
			    	   ],
						listeners:{
							'select':function(selModel,record,index) {
								var curchkamt = record.get('amount')-record.get('checkAmount');
								record.set('currentCheckAmount',curchkamt);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'deselect':function(selModel,record,index) {
								record.set('currentCheckAmount',0);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'edit':this.onEdit,
							'beforeedit':this.onBeforeEdit,
							'beforeselect':this.onBeforeSelect,
							'beforedeselect':this.onBeforeDeselect
						}
			       },{
			    	   xtype:'splitter'
			       },
			       {
			    	   xtype:'grid',
			    	   flex:1,
			    	   selModel:{selType:'checkboxmodel',checkOnly:true},
					   multiSelect:true,//运行多选
					   features: [{
					       ftype: 'summary'
					   }],
					   plugins: [
							       {
							    	   ptype:'cellediting',
							    	   clicksToEdit: 1
							       }
					   ],
			    	   columns:[
								   {header:'年份',dataIndex:'fyear',width:50,align:'right'},
								   {header:'期间',dataIndex:'period',width:50,align:'right'},
						       {
						    	   header:'单据编号',dataIndex:'arpBillCode',width:100,
						    	   summaryType:'count',summaryRenderer: function(value, summaryData, dataIndex) {return '<b>' + Ext.String.format('合计[{0}]:', value) + '</b>'; }
						       },
							   {header:'单据类型',dataIndex:'arpBillName',width:80},
							   {header:'日期',dataIndex:'billDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d')},
							   {header:'客户编码',dataIndex:'Customer',filterable:true,width:80,renderer:function(value,metaData,record){return record.getcustomer().get('customerCode');}},
							   {header:'客户名称',dataIndex:'customer',width:250,renderer:function(value,metaData,record){return record.getcustomer().get('customerName');}},
							   {header:'应收金额',dataIndex:'amount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {header:'已核销金额',dataIndex:'checkAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {
								   header:'本次核销金额',dataIndex:'currentCheckAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00'),
								   editor: {
					                    xtype: 'numberfield',
					                    allowBlank: false,
		                	        	fieldStyle:'text-align:right',
		                	        	allowDecimals: true
								   }
							   },
							   {header:'部门',dataIndex:'dept',width:65,renderer:function(value,metaData,record){return record.getdept().get('deptName');}},
							   {header:'业务员',dataIndex:'emp',width:65,renderer:function(value,metaData,record){return record.getemp().get('empName');}},
							   {header:'制单人',dataIndex:'maker',width:65,renderer:function(value,metaData,record){return record.getmaker().get('empName');}},
							   {header:'备注',dataIndex:'remark',width:200}
			    	   ],
						listeners:{
							'select':function(selModel,record,index) {
								var curchkamt = record.get('amount')-record.get('checkAmount');
								record.set('currentCheckAmount',curchkamt);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'deselect':function(selModel,record,index) {
								record.set('currentCheckAmount',0);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'edit':this.onEdit,
							'beforeedit':this.onBeforeEdit,
							'beforeselect':this.onBeforeSelect,
							'beforedeselect':this.onBeforeDeselect
						}
			       }
			]
		});
		var apayTransferSettle = Ext.create('Ext.panel.Panel',{
			title:'应付款转销',
			itemId:'transfersettle',
		    layout: {
		        type: 'vbox',       // Arrange child items vertically
		        align: 'stretch'    // Each takes up full width
		    },
			items:[
			       {
			    	   xtype:'grid',
			    	   selModel:{selType:'checkboxmodel',checkOnly:true},
					   multiSelect:true,//运行多选
					   features: [{
					       ftype: 'summary'
					   }],
					   plugins: [
							       {
							    	   ptype:'cellediting',
							    	   clicksToEdit: 1
							       }
					   ],
			    	   columns:[
								   {header:'年份',dataIndex:'fyear',width:50,align:'right'},
								   {header:'期间',dataIndex:'period',width:50,align:'right'},
						       {
						    	   header:'单据编号',dataIndex:'arpBillCode',width:100,
						    	   summaryType:'count',summaryRenderer: function(value, summaryData, dataIndex) {return '<b>' + Ext.String.format('合计[{0}]:', value) + '</b>'; }
						       },
							   {header:'单据类型',dataIndex:'arpBillName',width:80},
							   {header:'日期',dataIndex:'billDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d')},
							   {header:'客户编码',dataIndex:'Customer',filterable:true,width:80,renderer:function(value,metaData,record){return record.getcustomer().get('customerCode');}},
							   {header:'客户名称',dataIndex:'customer',width:250,renderer:function(value,metaData,record){return record.getcustomer().get('customerName');}},
							   {header:'应付金额',dataIndex:'amount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {header:'已核销金额',dataIndex:'checkAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {
								   header:'本次核销金额',dataIndex:'currentCheckAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00'),
								   editor: {
					                    xtype: 'numberfield',
					                    allowBlank: false,
		                	        	fieldStyle:'text-align:right',
		                	        	allowDecimals: true
								   }
							   },
							   {
								   header:'转销客户',width:200,dataIndex:'transferCustName',
								   editor:{
			  			    	    	xtype: 'triggerfield',
			  			    	    	name:'customer',
			  			    	    	emptyText:'请输入转出客户编码或名称',trigger1Cls:Ext.baseCSSPrefix + 'form-search-trigger',
			  			    	    	onTriggerClick:function(e){e.keyCode=e.ENTER;this.fireEvent('specialkey',this,e);},
			  			    	    	listeners:{
			  			    	    		specialkey:this.onFindTransferCust,
			  			    	    		change:this.onClearTransferCust
			  			    	    	}
								   }
							   },
							   {header:'部门',dataIndex:'dept',width:65,renderer:function(value,metaData,record){return record.getdept().get('deptName');}},
							   {header:'业务员',dataIndex:'emp',width:65,renderer:function(value,metaData,record){return record.getemp().get('empName');}},
							   {header:'制单人',dataIndex:'maker',width:65,renderer:function(value,metaData,record){return record.getmaker().get('empName');}},
							   {header:'备注',dataIndex:'remark',width:200}			    	            
			    	   ],
						listeners:{
							'select':function(selModel,record,index) {
								var curchkamt = record.get('amount')-record.get('checkAmount');
								record.set('currentCheckAmount',curchkamt);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'deselect':function(selModel,record,index) {
								record.set('currentCheckAmount',0);
								selModel.getStore().commitChanges();
								this.getView().refresh();
							},
							'edit':this.onEdit,
							'beforeedit':this.onBeforeEdit,
							'beforeselect':this.onBeforeSelect,
							'beforedeselect':this.onBeforeDeselect
						}
			       }
			]
		});
		this.items = [
		  		    {
		  		    	xtype: 'form',
		  		    	header:false,
		  		    	region: 'north',
		  		    	height: 60,
		  		    	border: false,
		  		    	buttonAlign: 'left',
		  		    	layout: 'hbox',
		  		    	fieldDefaults:{
		  		    		labelStyle:'text-align:right',
		  		    		margin:'20 10 10 10',
		  		    	},
		  		    	items:[
		  			    	    {xtype: 'hiddenfield',name:'custId',value:this.custId},
//		  			    	    {
//		  			    	    	xtype:'datefield',name:'begDate',fieldLabel:'开始日期',value:new Date(),format:'Y-m-d'
//		  			    	    },
//		  			    	    {
//		  			    	    	xtype:'datefield',name:'endDate',fieldLabel:'截止日期',value:new Date(),format:'Y-m-d'
//		  			    	    },
		  			    	    {
		  			    	    	xtype: 'triggerfield',
		  			    	    	name:'customer',
		  			    	    	fieldLabel:'核销客户:',
		  			    	    	width:400,
		  			    	    	value:this.custName,
		  			    	    	emptyText:'请输入客户编码或名称',trigger1Cls:Ext.baseCSSPrefix + 'form-search-trigger',
		  			    	    	onTriggerClick:function(e){e.keyCode=e.ENTER;this.fireEvent('specialkey',this,e);}
		  			    	    },		    	    
		  			    	    {xtype: 'button',text:'查询',margin:'20 10 10 10',action:'search',iconCls:'bill-find-button'}
		  		    	]
		  		    },
		  		    {
		  		    	xtype:'tabpanel',
		  		    	activeTab: 0,
		  		    	plain: true,
		  		    	region: 'center',
		  		    	items:[
							payBillSettle,
							refundBillSettle,
							apayOffsetarecSettle,
							apayTransferSettle
		  		    	]
		  		    }
		];
    	this.tbar=[
       			{xtype:'button',text:'核销',action:'check',iconCls:'button-rp-check'}
       	],
		this.callParent(arguments);
	},
	onEdit:function(editor,e) {
		e.record.commit();
		e.grid.getView().refresh();
		this.up().up().up().setEditing(false);
	},
	
	onBeforeEdit:function(editor,e) {
		if(e.field == 'currentCheckAmount' || e.field == 'transferCustName') {
			this.up().up().up().setEditing(true);
		}
	},
	onBeforeSelect:function() {
		if(this.up().up().up().getEditing()) {
			return false;
		}
	},
	onBeforeDeselect:function() {
		if(this.up().up().up().getEditing()) {
			return false;
		}
	},
	onFindTransferCust:function(field,e) {
		var custIdField = field.up('panel').up('panel').up('panel').up('panel').down('form')
							.down('hiddenfield[name=custId]');
		var record = field.up('grid').getSelectionModel().getLastSelected();
		if(e.getKey() == e.ENTER && field.value != '') {
	    	var view=Ext.create('TS.view.base.CustomerSearchDialog');
	    	view.setVal(field.value);
	    	view.on({
			    selected: function(records){
			    	if(records.length == 0) {
			    		Ext.MessageBox.alert('ThinkGsp','未检索到任何客户信息!');
			    	} else {
			    		if(custIdField.getValue() == records[0].get('customerId')) {
			    			Ext.Msg.show({
			    				title:'警告',
			    				msg:'转出客商不能与原始客商相同!',
			    				buttons:Ext.Msg.OK,
			    				icon:Ext.Msg.WARNING
			    			});
			    			record.set('transferCustId',null);
			    			return false;
			    		}
			    		record.set('transferCustId',records[0].get('customerId'));
			    		record.set('transferCustName','[' + records[0].get('customerCode') + ']' + records[0].get('customerName'));
			    		record.commit();
			    	}
			    },
			    scope: this
			});
	    	view.show();	
		}
	},
	onClearTransferCust:function(field,e) {
		var record = field.up('grid').getSelectionModel().getLastSelected();
		if(field.value == '') {
			record.set('transferCustId',null);
			record.commit();
		}
	}
});